/*
 * input.h
 *
 *  Created on: 05/06/2011
 *      Author: George Ferreira
 */
#ifndef INPUT_H_
#define INPUT_H_


using namespace std;


#include <iostream>
#include <string>
#include "defines.h"

class Input {

public:
	vector<string> params;
	string interface;
	string sourcefile;
	string filter;

	int sourcename;


	Input(int c, char **v){
		this->sourcefile = "";
		this->interface = "";
//		Check for maximum parms
		if ( c > MAX_NUM_PARAM ){
			cout << "Muitos parametros passados" << endl;
			exit(1);
		}

//		Get user parameters
		this->params.resize(c);

//		For each parameter set it into a C++ standard string class
		for(int i= 0; i<c; i++){

			this->params[i] = string(v[i]);
		}


		this->parseInputParams(this->params);
	}


//  Check user input e parameters. return -1 in success any thing bigger than -1 is a error;
	int parseInputParams(vector<string> params){
		string name;
		string value;

		for(unsigned int i=1; i < params.size()-1; i += 2){
			name  = params[i];
			value = params[i+1];


			// network interface
			if ( name == "-i"){

				this->sourcename = INTERFACE;
				this->interface = value;

			// network flow file
			}else if ( name == "-f" ){

				this->sourcename = FILESOURCE;
				this->sourcefile = value;

			// pcap filter
			}else if ( name == "-F"){

				this->filter = value;

			// quantidade de parametros examinados
			}else{
				return 1;
			}
		}

		return -1;
	}

};
#endif /* INPUT_H_ */
